<template>
    <el-container class="content">
        <el-main>
            <el-container class="white-block box full" v-loading="loading">
                <el-header :height="'auto'">
                    <div class="toolbar">
                        <div>
                            <el-input v-model="companyName" placeholder="请输入名称" class="input short mr10"
                                      size="small"></el-input>
                            <el-select v-model="resourcesValue" placeholder="商企类型" class="select short mr10"
                                       size="small">
                                <el-option
                                    v-for="item in resourcesOptions"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                            <el-select v-model="currentState" placeholder="当前状态" class="select short mr10"
                                       size="small">
                                <el-option
                                    v-for="item in currentOptions"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                            <el-date-picker v-model="searchTime" size="small" class="short mr10"
                                            type="daterange"
                                            range-separator="~"
                                            start-placeholder="开始日期"
                                            end-placeholder="结束日期">
                            </el-date-picker>
                            <el-button class="primary" @click="getList()" size="small">查询</el-button>
                            <el-button class="minor" @click="reset()" size="small">重置</el-button>
                        </div>
                    </div>
                </el-header>
                <el-main class="mt10">
                    <table-example ref="table" :data="tableData" :tableColumn="header" :slotColumns="slotColumns"
                                   :stripe="true">
                        <template slot="approvalResult" slot-scope="scope">
                            <span v-if="scope.row.approvalResult==0">审核中</span>
                            <span v-else-if="scope.row.approvalResult==1">审核通过</span>
                            <span v-else-if="scope.row.approvalResult==2" class="error">审核未通过</span>
                        </template>
                        <template slot="operation" slot-scope="scope">
                            <div class="operation" v-if="scope.row.approvalResult==0">
                                <el-link type="primary" :underline="false" @click="approval(scope.row, 1)">通过</el-link>
                                <el-link type="primary" :underline="false" @click="approval(scope.row, 2)">拒绝</el-link>
                            </div>
                        </template>
                    </table-example>
                </el-main>
                <el-footer :height="'auto'" class="mt20">
                    <page :data="page" @jumpPage="getList"></page>
                </el-footer>
            </el-container>
            <!--            <transition name="slide">-->
            <!--                <router-view @upload="getList"></router-view>-->
            <!--            </transition>-->
        </el-main>
    </el-container>
</template>

<script>
    import tableExample from '../components/table'
    import page from '../components/pagination'

    export default {
        data() {
            return {
                companyName: '',
                searchTime: '',
                resourcesOptions: [
                    {
                        label: '',
                        value: ''
                    },
                    {
                        label: '企业',
                        value: 1
                    },
                    {
                        label: '商超',
                        value: 2
                    }
                ],
                resourcesValue: '',
                currentOptions: [
                    {
                        label: '',
                        value: ''
                    },
                    {
                        label: '审核中',
                        value: 1
                    },
                    {
                        label: '已通过',
                        value: 2
                    },
                    {
                        label: '未通过',
                        value: 3
                    }
                ],
                currentState: '',
                tableData: [],
                header: [
                    {
                        prop: 'companyName',
                        label: '名称',
                        minWidth: '200',
                        align: 'center',
                        headerAlign: 'center'
                    },
                    {
                        prop: 'businessType',
                        label: '类型',
                        minWidth: '100',
                        align: 'center',
                        headerAlign: 'center'
                    },
                    {
                        prop: 'industry',
                        label: '行业',
                        minWidth: '100',
                        align: 'center',
                        headerAlign: 'center'
                    },
                    {
                        prop: 'legalPerson',
                        label: '法人/业主',
                        minWidth: '100',
                        align: 'center',
                        headerAlign: 'center'
                    },
                    {
                        prop: 'reWorkTime',
                        label: '复工时间',
                        width: '100',
                        align: 'center',
                        headerAlign: 'center'
                    },
                    {
                        prop: 'reWorkNum',
                        label: '复工人数',
                        align: 'center',
                        minWidth: '100'
                    },
                    {
                        prop: 'approvalResult',
                        label: '状态',
                        align: 'center',
                        minWidth: '100'
                    },
                    {
                        prop: 'createTime',
                        label: '申请时间',
                        align: 'center',
                        minWidth: '150'
                    },
                    {
                        prop: 'operation',
                        label: '操作',
                        align: 'center',
                        minWidth: '100',
                        fixed: 'right'
                    }
                ],
                slotColumns: ['approvalResult', 'operation'],
                page: {
                    total: 120,
                    size: 10,
                    current: 1,
                    pages: 12
                },
                loading: false,
                index: 1
            }
        },
        mounted() {
            this.getList()
        },
        methods: {
            // 获取列表数据
            getList(index) {
                this.loading = true
                if (index) this.index = index
                this.$http.get('/resumption/getApplyInfo', {
                    startTime: this.searchTime[0] ? this.$filter.timeFormat(this.searchTime[0], 'YYYY-MM-DD') : '', // 起始时间
                    endTime: this.searchTime[1] ? this.$filter.timeFormat(this.searchTime[1], 'YYYY-MM-DD') : '', // 结束时间
                    // resName: this.resName,
                    // resType: this.resourcesValue,
                    current: this.index || 1,
                    size: 15
                    // state: this.currentState
                }).then(result => {
                    this.loading = false
                    if (result.success) {
                        this.tableData = result.data.records
                        this.page = result.data
                        delete this.page['records']
                    }
                }).catch(() => {
                    this.loading = false
                })
            },
            // 重置操作
            reset() {
                this.searchTime = ''
                this.companyName = ''
                this.resourcesValue = ''
                this.currentState = ''
                this.getList(1)
            },
            approval(row, type) {
                this.$http.post('/resumption/approval', {
                    id: row.id,
                    approvalResult: type
                }).then(result => {
                    this.getList()
                })
            }
        },
        components: {
            tableExample,
            page
        }
    }
</script>

<style scoped lang="less">
    .content {
    }
</style>
